<template>
  <div class="page">
    <div class="main">
      <div class="subnav">
        <div class="searchLeft">
          <span>年份</span>
        </div>
        <div class="searchRight">
        </div>
      </div>
      <div class="list">
        <el-scrollbar class="page-component__scroll" style="height:100%">
          <div style="height:700px;">
            <el-table
              ref="multipleTable"
              :data="tableData"
              tooltip-effect="dark"
              height="600"
              style="width: 100%"
              @selection-change="handleSelectionChange"
            >
              <el-table-column prop="name" label="任务名称"> </el-table-column>

              <el-table-column fixed="right" width="300" label="操作">
                <template slot-scope="scope">
                  <el-button
                    type="primary"
                    size="mini"
                    @click="setGrade(scope.row)"
                    >打分</el-button
                  >
                  <el-button type="primary" size="mini">修改</el-button>
                  <el-button type="primary" size="mini">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-scrollbar>
      </div>
    </div>

    <!-- 弹出备注输入框 -->
    <el-dialog title="备注" :visible.sync="dialogVisible" width="30%" center>
      <el-input
        type="textarea"
        :rows="8"
        placeholder="请输入内容"
        v-model="textarea"
      >
      </el-input>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      dialogVisible: false,
      dialogGrade: false,
      options: [],
      value: "",
      value1: true,
      input: "",
      tableData: [],
      total: 0,
      multipleSelection: [],
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
      textarea: "",
      objCurr: {
        type: true,
        id: "",
        taskId: "",
        year: "",
        time: "",
        score: ""
      },
      quarterList: [1, 2, 3, 4],
      input2: ""
    };
  },
  mounted() {
    this.getListByPage();
  },
  methods: {
    setGrade(val) {
      console.log(val);
      for (const key in this.objCurr) {
        this.objCurr[key] = "";
      }
      this.objCurr.taskId = val.id;
      this.objCurr.type = true;
      this.dialogGrade = true;
    },
    // 点击列表打分确认按钮
    dataGrade() {
      let _this = this.objCurr;
      if (_this.year == "" || _this.time == "" || _this.score == "") {
        this.$message.error("请用户填填完输入框");
        return;
      }

      if (!/(^[1-9]\d*$)/.test(_this.score)) {
        this.$message.error("请用户在分数内写入1-100的正整数");
        return;
      }
      this.$axios
        .post(`/taskScore/add`, this.objCurr, 2)
        .then(res => {
          if (res.code == 200) {
            console.log(res);
            this.$message({
              message: "数据更新成功",
              type: "success"
            });
            this.dialogGrade = false;
            this.getListByPage();
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    dataTotal(val) {
      this.pageNum = val;
    },
    // 表格数组
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 列表查看按钮
    routerPath(val) {
      this.$router.push({
        path: "/unitboyScore",
        query: { subtasksId: val.subtasksId }
      });
    },
    // 编写备注
    dataRemark() {
      this.dialogVisible = true;
    },
    // 获取数据列表
    getListByPage() {
      this.$axios
        .post(`/task/getAllTask1`)
        .then(res => {
          if (res.code == 200) {
            this.tableData = res.data;
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
  }
};
</script>
<style scoped>
.page {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.main {
  width: 100%;
  height: 100%;
  padding: 0 20px;
  background: #fff;
}
.subnav {
  float: left;
  width: 100%;
  height: 60px;
  line-height: 60px;
  padding: 0 20%;
}
.searchLeft {
  float: left;
  width: 400px;
  /* height: 40px; */
}
.searchLeft > button {
  width: 100px;
  height: 40px;
  background: #409eff;
  color: #fff;
  border: 0px;
  font-size: 16px;
  text-align: center;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  position: relative;
  left: -8px;
  top: 1px;
}
.searchRight {
  float: left;
  width: auto;
}
.searchRight > span {
  display: inline-block;
  width: 80px;
  height: auto;
  font-size: 14px;
  text-align: center;
  margin-left: 20px;
}
.el-scrollbar__wrap {
  overflow-x: hidden;
}
.page-component__scroll {
  height: 100%;
}
.list {
  width: 100%;
  height: 100%;
  padding-top: 60px;
  padding-bottom: 60px;
}
.laypage {
  width: 100%;
  height: 60px;
  position: relative;
  top: -60px;
  text-align: right;
}
</style>
<style>
.el-scrollbar__wrap {
  overflow: visible;
  overflow-y: scroll;
}
</style>
